//
//  SDLoginViewController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/5/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDLoginViewController.h"

#define padding 20
@interface SDLoginViewController ()

@property (nonatomic, strong) UIImageView *logoView;
@property (nonatomic, strong) UIImageView *logoLabel;
@property (nonatomic, strong) UITextField *accountTf;
@property (nonatomic, strong) UITextField *passwordTF;
@property (nonatomic, strong) UIButton    *loginButton;

@end

@implementation SDLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupLayout];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self.view endEditing:YES];
}

- (void)setupLayout{
    
    [self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_topLayoutGuide).mas_offset(padding*3);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    [self.logoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.logoView.mas_bottom);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.equalTo(self.logoView);
        
    }];
    [self.accountTf mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.logoLabel.mas_bottom).mas_offset(padding);
        make.leading.mas_equalTo(padding);
        make.trailing.mas_equalTo(-padding);
        
    }];
    [self.passwordTF mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.mas_equalTo(padding);
        make.trailing.mas_equalTo(-padding);
        make.top.mas_equalTo(self.accountTf.mas_bottom).mas_offset(padding);
        
    }];
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(padding);
        make.trailing.mas_equalTo(-padding);
        make.top.mas_equalTo(self.passwordTF.mas_bottom).mas_offset(padding);
    }];
}

- (void)loginClickButton:(UIButton *)sender{
    
    
}

#pragma mark
#pragma mark - lazy 控件懒加载
- (UIImageView *)logoView{
    if (_logoView == nil) {
        _logoView = [[UIImageView alloc] init];
        _logoView.image = [UIImage imageNamed:@"product_img_logo_nor.png"];
        [self.view addSubview:_logoView];
    }
    return _logoView;
}

- (UIImageView *)logoLabel{
    if (_logoLabel == nil) {
        _logoLabel = [[UIImageView alloc] init];
        _logoLabel.image = [UIImage imageNamed:@"product_text_logo_nor.png"];
        [self.view addSubview:_logoLabel];
    }
    return _logoLabel;
}
- (UITextField *)accountTf{
    if (_accountTf == nil) {
        _accountTf = [[UITextField alloc] init];
        _accountTf.clearButtonMode = UITextFieldViewModeWhileEditing;
        _accountTf.borderStyle = UITextBorderStyleRoundedRect;
        _accountTf.placeholder = @"请输入账户";
        [self.view addSubview:_accountTf];
    }
    return _accountTf;
}
- (UITextField *)passwordTF{
    if (_passwordTF == nil) {
        _passwordTF = [[UITextField alloc] init];
        _passwordTF.placeholder = @"请输入账户";
        _passwordTF.borderStyle = UITextBorderStyleRoundedRect;
        _passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.view addSubview:_passwordTF];
    }
    return _passwordTF;
}
- (UIButton *)loginButton{
    if(_loginButton == nil){
        
        _loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginButton setTitle:@"登陆" forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _loginButton.backgroundColor = kThemeColor;
        [_loginButton addTarget:self action:@selector(loginClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_loginButton];
        
    }
    return _loginButton;
}
@end
